<?php 
class Mahasiswa_model extends CI_Model {
	
	var $data;
	
	function get_all_data(){
		$query = $this->db->get('mahasiswa');
		if ($query->num_rows() > 0)
		{
			return $query->result();
		}
		else
		{
			return FALSE;
		}
	}
	
	function get_jum_data(){
		$query = $this->db->query('select count(*) as jumlah from mahasiswa');
		if ($query->num_rows() > 0)
		{
			return $query->row();
		}
		else
		{
			return FALSE;
		}
	}
	
	function get_last_id(){
		$query = $this->db->query('select * from mahasiswa order by nim desc limit 1 ');
		if ($query->num_rows() > 0)
		{
			return $query->row();
		}
		else
		{
			return FALSE;
		}
	}

	function get_data_by_id($id){
		$this->db->where('nim', $id);
		$query = $this->db->get('mahasiswa');
		if ($query->num_rows() > 0)
		{
			return $query->row_array();
		}
		else
		{
			return FALSE;
		}
	}

	function fill_data()
	{
		$this->data = array(
			'nim' => $this->input->post('nim'),
			'kode_dosen' => $this->input->post('kode_dosen'),			
			'nama' => $this->input->post('nama'),
			'hp' => $this->input->post('hp'),
			'email' => $this->input->post('email')
		);
	}
	
	//Check for duplicate nim mahasiswa
	function check_name($id = '')
	{
		$this->db->where('nim', $this->data['nim']);
		if($id != '') $this->db->where('nim !=', $id);
		$query = $this->db->get('mahasiswa');

		if ($query->num_rows() > 0)
		{
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}	

	function insert_data()
	{
		$insert = $this->db->insert('mahasiswa', $this->data);
		return $insert;
	}
	
	function tambah($data)
	{
		$tambah=$this->db->insert('mahasiswa',$data);
		return $tambah;
	}

	function update_data($id)
	{
		$this->db->where('nim', $id);
		$update = $this->db->update('mahasiswa', $this->data);
		return $update;
	}
	
	function update($id, $data)
	{
		$this->db->where('nim',$id);
		$update = $this->db->update('mahasiswa',$data);
		return $update;
	}

	function delete_data($id){
		$this->db->where('nim', $id);
		$delete = $this->db->delete('mahasiswa');
		return $delete;
	}
	function hapus($id)
	{
		$this->db->where('nim',$id);
		$hapus = $this->db->delete('mahasiswa');
		return $hapus;
	}
	
	function per_id($id)
	{
		$this->db->where('nim',$id);
		$query=$this->db->get('mahasiswa');
		return $query->result();
	}

}

/* End of file mahasiswa_model.php */
/* Location: ./application/models/mahasiswa_model.php */
